<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Scopes\IdScope;
use Illuminate\Database\Eloquent\Builder;

/**
 * App\Models\Country
 *
 * @property int $id
 * @property string $name
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Post[] $posts
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Country ofId($id)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Country whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Country whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Country whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Country whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Country extends Model
{
    // use SoftDeletes;

    // protected $dates = ['deleted_at'];
    protected $fillable = ['name'];

    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        // static::addGlobalScope('age', function (Builder $builder) {
        //     $builder->where('id', '>', 3);
        // });
    }

    //获取指定国家的所有文章
    public function posts() {
    	return $this->hasManyThrough('App\Models\Post', 'App\Models\User');
    }
    
    // 设置一个本地作用域
    public function scopeOfId($query, $id)
    {
        return $query->where('id', $id);
    }
}
